<?php

namespace App\Ordersys\Controllers\Admin;

use App\Base\Controllers\Controller;
use App\Ordersys\Contracts\OrdersysChannelInterface;
use Illuminate\Http\Request;

/**
 * 渠道
 * Class ChannelController
 * @package App\Ordersys\Controllers\Admin
 */
class ChannelController extends Controller
{
    /**
     * 产品接口
     * @return OrdersysChannelInterface
     */
    public function getOrdersysChannelInterface()
    {
        return app()->make(OrdersysChannelInterface::class);
    }

    public function index(Request $request)
    {
        if ($request->getMethod() == 'POST') {
            $where = function ($query) use ($request) {
                $name = $request->input("name");
                if (!empty($name)) {
                    $query->where("name", "like", '%' . $name . '%');
                }
                $wx_no = $request->input("wx_no");
                if (!empty($wx_no)) {
                    $query->where("wx_no", "like", '%' . $wx_no . '%');
                }
            };
            return $this->getOrdersysChannelInterface()->getList($where);
        }
        return view("ordersys.channel.index");
    }

    public function add(Request $request)
    {
        if ($request->getMethod() == 'POST') {
            $where = function ($query) use ($request) {
                $name = $request->input("name");
                if (!empty($name)) {
                    $query->where("name", "like", '%' . $name . '%');
                }
                $wx_no = $request->input("wx_no");
                if (!empty($wx_no)) {
                    $query->where("wx_no", "like", '%' . $wx_no . '%');
                }
            };
            return $this->getOrdersysChannelInterface()->saveData($where);
        }
        return view("ordersys.channel.add");
    }

    public function edit(Request $request)
    {

    }

    public function del(Request $request)
    {

    }
}